package com.robinmouren.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.robinmouren.annotation.AutoFill;
import com.robinmouren.constant.AutoFillConstant;
import com.robinmouren.constant.MessageConstant;
import com.robinmouren.dto.*;
import com.robinmouren.entity.TransportRoute;
import com.robinmouren.enumeration.OperationType;
import com.robinmouren.exception.NullOrderInfoException;
import com.robinmouren.result.Result;
import com.robinmouren.service.impl.DriverServiceImpl;
import com.robinmouren.service.impl.TransportRouteServiceImpl;
import com.robinmouren.vo.DriverPageVo;
import com.robinmouren.vo.ToBeQuoteVo;
import com.robinmouren.vo.TransportRouteVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 司机表，记录司机车辆信息 前端控制器
 * </p>
 *
 * @author Robinmouren
 * @since 2024-05-18
 */
@RestController
@RequestMapping("/driver")
@Slf4j
public class DriverController {

    @Autowired
    private TransportRouteServiceImpl transportRouteService;
    @Autowired
    private DriverServiceImpl driverService;

    /**
     * 司机创建运输路线
     * @param dto
     * @return
     */
    @PostMapping("/transport/create")
    @AutoFill(value = OperationType.RECORDING,context = AutoFillConstant.DRIVER_CREATE_QUOTE)
    public Result transportCreate(@RequestBody TransportCreateDto dto){
        log.info("司机创建运输路线，信息：{}",dto);

        transportRouteService.create(dto);
        return Result.success();
    }


    /**
     * 司机运输路线分页查询
     * @param pageDto
     * @return
     */
    @PostMapping("/transport/page")
    public Result<Page<TransportRouteVo>> transportRoutePage(@RequestBody QuotationPageDto pageDto){
        log.info("司机运输路线分页查询，信息：{}",pageDto);
        Page<TransportRouteVo> voPage = transportRouteService.transportPage(pageDto);
        return Result.success(voPage);
    }

    // 添加了一行测试数据

    /**
     * 根据id获取运输信息
     * @param id
     * @return
     */
    @GetMapping("/transport/getById")
    public Result<TransportRoute> transportRoutePage(String id){
        log.info("司机根据id获取运输信息，id：{}",id);
        TransportRoute route = transportRouteService.getById(id);
        if(route == null){
            throw new NullOrderInfoException(MessageConstant.ROUTER_IS_NOT_EXIST);
        }
        return Result.success(route);
    }


    /**
     * 根据id删除运输信息
     * @param id
     * @return
     */
    @DeleteMapping("/transport/delById")
    @AutoFill(value = OperationType.RECORDING,context = AutoFillConstant.DRIVER_DELETE_QUOTE)
    public Result transportRouteDel(String id){
        log.info("司机根据id删除运输信息，id：{}",id);
        transportRouteService.removeById(id);
        return Result.success();
    }


    /**
     * 司机信息分页查询
     * @param pageDto
     * @return
     */
    @PostMapping ("/page")
    public Result<Page<DriverPageVo>> driverPage(@RequestBody DriverPageDto pageDto){
        log.info("司机信息分页查询，分页信息：{}",pageDto);
        Page<DriverPageVo> page = driverService.driverPage(pageDto);
        return Result.success(page);
    }




    /**
     * 司机待报价分页查询
     * @param dto
     * @return
     */
    @PostMapping ("/toBe/page")
    public Result<Page<ToBeQuoteVo>> toBePage(@RequestBody QuotationPageDto dto){
        log.info("司机待报价分页查询，分页信息：{}",dto);
        Page<ToBeQuoteVo> page = driverService.toBePage(dto);
        return Result.success(page);
    }


    /**
     * 司机报价
     * @param dto
     * @return
     */
    @PostMapping ("/toBe/quote")
    @AutoFill(value = OperationType.RECORDING,context = AutoFillConstant.DRIVER_QUOTE)
    public Result driverQuote(@RequestBody DriverQuoteDto dto){
        log.info("司机报价，信息：{}",dto);
        driverService.driverQuote(dto);
        return Result.success();
    }
}
